
# Install the required libraries that are available as debs.
sudo apt-get update
sudo apt-get install -y \
    clang \
    cmake \
    g++ \
    git \
    google-mock \
    libboost-all-dev \
    libcairo2-dev \
    libceres-dev \
    libcurl4-openssl-dev \
    libeigen3-dev \
    libgflags-dev \
    libgoogle-glog-dev \
    liblua5.2-dev \
    libsuitesparse-dev \
    lsb-release \
    ninja-build \
    python3-sphinx \
    stow

# Install Protocol Buffers and Abseil if available.
# No need to build it ourselves.
case "$(lsb_release -sc)" in
    jammy|bullseye)
        sudo apt-get install -y libgmock-dev protobuf-compiler libabsl-dev ;;
    focal|buster)
        sudo apt-get install -y libgmock-dev protobuf-compiler ;;
    bionic)
        ;;
esac

thirdparty_dir="/home/xxty/trobot/trobot_ros/thirdparty"
rm -rf $thirdparty_dir/abseil-cpp/build
rm -rf $thirdparty_dir/protobuf/build
rm -rf $thirdparty_dir/cartographer/build

# Install abseil
# git clone https://github.com/abseil/abseil-cpp.git
# cd abseil-cpp
# git checkout 215105818dfde3174fe799600bb0f3cae233d0bf # 20211102.0
cd $thirdparty_dir/abseil-cpp/
mkdir build && cd build
cmake -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  -DCMAKE_INSTALL_PREFIX=/usr/local/stow/absl \
  ..
ninja
sudo ninja install
cd /usr/local/stow
sudo stow absl

# Build and install proto3.
# git clone https://github.com/google/protobuf.git
# cd protobuf
# git checkout tags/${VERSION}
cd $thirdparty_dir/protobuf/
mkdir build && cd build
cmake -G Ninja \
  -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  -DCMAKE_BUILD_TYPE=Release \
  -Dprotobuf_BUILD_TESTS=OFF \
  ../cmake
ninja
sudo ninja install


# Build and install Cartographer.
# cd cartographer
cd $thirdparty_dir/cartographer/
mkdir build && cd build
cmake .. -G Ninja
ninja
CTEST_OUTPUT_ON_FAILURE=1 ninja test
sudo ninja install